{$CLEO .cm}
{$USE CLEO+}


0000:
const
    MISSION_CAR = 0@
    damage_dealt = 1@ 
    Voice_clip = 2@ 
    Line_is_playing = 3@
    Line_number_played_times =4@ 
    Partice_attach_to_vehicle = 25@
    Location = 449@
    CHOSEN_MODEL = 700@
end
MODEL.Load(#HUNTLEY)
MODEL.Load(#STAFFORD)
MODEL.Load(#INTRUDER)
MODEL.Load(#COPCARVG)
MODEL.Load(#FIRETRUK)
MODEL.Load(#AMBULAN)
MODEL.Load(#FELTZER)
MODEL.Load(#INFERNUS)
MODEL.Load(#WMYBMX)
load_requested_models

//Start position

:RELOAD_MODELS
wait 0
if and
Model.Available(#STAFFORD)
Model.Available(#HUNTLEY)
Model.Available(#INTRUDER)
Model.Available(#COPCARVG)
Model.Available(#INFERNUS) 
Model.Available(#FELTZER) 
Model.Available(#WMYBMX)

jf @RELOAD_MODELS

$onmission = 2 


:back_the_top

     fade 0 1000
     wait 1000
     fade 1 1000
     CHOSEN_MODEL = #HUNTLEY

    REPEAT 
    WAIT 0
    UNTIL  09E7:   player $PLAYER_CHAR not_frozen

    actor_remove_from_car_and_put_at player1  300.9065 -6774.1245 7.92
    actor.Angle(player1)=   15.293
    gosub @spawn_player2 
    0395: clear_area 1 at 281.0754 -7684.7461 12.8381 radius 999999999.0
 
////Start      
80@ = actor.Create(40, #WMYBMX, 319.0789, -6778.5962, 7.92)
actor.Angle( 80@ ) = 25.2787
060B: set_actor 80@ decision_maker_to 32 
actor.SetImmunities(  80@ , 1,1,1,1,1) 

015F: set_camera_position 282.9518 -7693.6021 8.1649  rotation 0.0 0.0 0.0
0160: set_camera_point_at 289.1259 -7692.5771 8.1649  switchstyle 2
 
    
    camera.Restore_WithJumpCut()
    actor_remove_from_car_and_put_at player1  301.1812 -6773.9429 7.92
    actor.Angle(player1)= 176.5372
    gosub @spawn_player2 
    //Begin the mission, with Bobby taking it's place 

    100@ = car.Create( #STAFFORD , 306.2981, -6785.9409, 7.92 )
    car.Angle( 100@ )= 319.1594
    car.Health( 100@ ) = 50000
    09C4: set_car 100@ gas_tank_explosion_enabled 0
    car.DoorStatus(100@,4)
    car.SetImmunities(100@,1,1,1,1,1)
    

    101@ = car.Create( #HUNTLEY , 299.7743, -6785.8569, 7.92 )
    car.Angle( 101@ )= 319.1594
    car.Health( 101@ ) = 50000
    09C4: set_car 101@ gas_tank_explosion_enabled 0
    car.DoorStatus(101@,4)
    car.SetImmunities(101@,1,1,1,1,1)
    
    
    102@ = car.Create( #INTRUDER , 289.1287, -6785.9614, 7.92 )
    car.Angle( 102@ )= 319.1594
    car.Health( 102@ ) = 50000
    09C4: set_car 102@ gas_tank_explosion_enabled 0
    car.DoorStatus(102@,4)
    car.SetImmunities(102@,1,1,1,1,1)
    
    103@ = car.Create( #COPCARVG , 280.5388, -6786.5654, 7.92 )
    car.Angle( 103@ )= 319.1594
    car.Health( 103@ ) = 50000
    09C4: set_car 103@ gas_tank_explosion_enabled 0
    car.DoorStatus(103@,4)
    car.SetImmunities(103@,1,1,1,1,1)
    
    104@ = car.Create( #FELTZER ,270.4688, -6787.4692, 7.92  )
    car.Angle( 104@ )= 319.1594
    car.Health( 104@ ) = 50000
    09C4: set_car 104@ gas_tank_explosion_enabled 0
    car.DoorStatus(104@,4)
    car.SetImmunities(104@,1,1,1,1,1)
     
    105@ = car.Create( #INFERNUS , 265.2428, -6787.1621, 7.92 )
    car.Angle( 105@ )= 319.1594
    car.Health( 105@ ) = 50000
    09C4: set_car 105@ gas_tank_explosion_enabled 0
    car.DoorStatus(105@,4)
    car.SetImmunities(105@,1,1,1,1,1)
     03BF: set_player $PLAYER_CHAR ignored_by_everyone 1 
     PLAYER.CanMove($PLAYER_CHAR)=FALSE      
    Partice_attach_to_vehicle=0  
    add_text_label '_TESTxx' "Test Drive"
    add_text_label '_TEST00' "STAFFORD"
    add_text_label '_TEST01' "HUNTLEY"
    add_text_label '_TEST02' "INTRUDER"
    add_text_label '_TEST03' "POLICE CAR"
    add_text_label '_TEST04' "FELTZER"
    add_text_label '_TEST05' "INFERNUS" 
    08D4: 76@ = create_panel_with_title '_TESTxx' position 29.0 170.0 width 180.0 columns 1 interactive 1 background 1 alignment 0  // Imports
    08DB: set_panel 76@ column 0 header 'DUMMY' data '_TEST00' '_TEST01' '_TEST02' '_TEST03' '_TEST04' '_TEST05' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY' 'DUMMY'  // Sunday // Monday // Tuesday // Wednesday // Thursday // Friday // Saturday
   
    while true 
    wait 0
    08D7: 81@  = panel 76@ active_row
        IF  00E1:   player 0 pressed_key 15
        THEN
         08DA: remove_panel 76@
           JUMP @CLEANUP_MISSION 
        END
 
         IF 81@==0
         THEN
            0679: put_camera_on_car 100@ with_offset 0.0 7.2 0.0 rotation 0.0 0.0 0.0 tilt 0.0 switchstyle 2
            IF 00E1:   player 0 pressed_key 16
            THEN
                CHOSEN_MODEL = #STAFFORD
                BREAK
            END
         END
         IF 81@==1
         THEN
            0679: put_camera_on_car 101@ with_offset 0.0 7.2 0.0 rotation 0.0 0.0 0.0 tilt 0.0 switchstyle 2
            IF 00E1:   player 0 pressed_key 16
            THEN
                CHOSEN_MODEL = #HUNTLEY
                BREAK
            END
         END
         IF 81@==2
         THEN
            0679: put_camera_on_car 102@ with_offset 0.0 7.2 0.0 rotation 0.0 0.0 0.0 tilt 0.0 switchstyle 2
            IF 00E1:   player 0 pressed_key 16
            THEN
                CHOSEN_MODEL = #INTRUDER
                BREAK
            END
         END
         IF 81@==3
         THEN
            0679: put_camera_on_car 103@ with_offset 0.0 7.2 0.0 rotation 0.0 0.0 0.0 tilt 0.0 switchstyle 2
            IF 00E1:   player 0 pressed_key 16
            THEN
                CHOSEN_MODEL = #COPCARVG
                BREAK
            END
         END
         IF 81@==4
         THEN
            0679: put_camera_on_car 104@ with_offset 0.0 7.2 0.0 rotation 0.0 0.0 0.0 tilt 0.0 switchstyle 2
            IF 00E1:   player 0 pressed_key 16
            THEN
                CHOSEN_MODEL = #FELTZER
                BREAK
            END
         END
         IF 81@==5
         THEN
            0679: put_camera_on_car 105@ with_offset 0.0 7.2 0.0 rotation 0.0 0.0 0.0 tilt 0.0 switchstyle 2
            IF 00E1:   player 0 pressed_key 16
            THEN
                CHOSEN_MODEL = #INFERNUS
                BREAK
            END
         END
         
         
         
    end 
     08DA: remove_panel 76@
     03BF: set_player $PLAYER_CHAR ignored_by_everyone 0 
     PLAYER.CanMove($PLAYER_CHAR)=TRUE 
     camera.Restore_WithJumpCut()
    //Wasteland ruins
    actor_remove_from_car_and_put_at player1  300.9065 -6774.1245 6.92
    actor.Angle(player1)=   15.293
    gosub @spawn_player2 

 
    MISSION_CAR = car.Create( CHOSEN_MODEL , 301.9927, -6767.0645, 6.92)
    car.Angle( MISSION_CAR )= 276.9513
    car.Health( MISSION_CAR ) = 50000
    09C4: set_car MISSION_CAR gas_tank_explosion_enabled 0    
    car.DoorStatus(MISSION_CAR ,0)
    car.SetMaxSpeed(MISSION_CAR, 200.0  ) 
    while true 
    wait 0

 
 if cheat "exit"
 then
     show_styled_text "~r~Aborted the Job!" 3000 5 
     jump @CLEANUP_MISSION
 end
        //Car is defined for the mission, use it and don't destroy it.
        if is_car_defined MISSION_CAR
        then
        //Support
           if  or
           $FPS_PLAYER2_CAMERA==1
           $FPS_PLAYER2_CAMERA==2 
           then
                0697: set_car MISSION_CAR remove_component 4 visible_effect_flag 0  
           
           else
                0698: set_car MISSION_CAR repair_componentB 4 
           end      
        
            if  actor.InCar(player1, MISSION_CAR)
            then
                if 0154:   actor $PLAYER_ACTOR in_zone 'SAN_AND'  // Easter Basin
    
                then
                    show_styled_text "~r~This car belongs to Railcity! ~w~Pay! $5000" 3000 5 
                    0109: player $PLAYER_CHAR money += -5000
                    018C: play_sound 1053 at 0.0 0.0 0.0
    
                    wait 3000
                   car.RemoveReferences(MISSION_CAR)
                   mission_cleanup
                   jump @back_the_top            
                end 
                0AD1: show_formatted_text_highpriority " %.1f - Speed" time 1 188@
                02E3: 188@ = car MISSION_CAR speed
                if 188@ >= 60.0
                then
                     0109: player $PLAYER_CHAR money += 1
                    0AD1: show_formatted_text_highpriority "~y~%f.1 - Speed ~g~Money!" time 1 188@
    
                end        
            end 
    
        
            if  Partice_attach_to_vehicle==1 
            then
             
                    show_styled_text "~r~You broke the car! ~w~Pay! $1000" 3000 5 
                    0109: player $PLAYER_CHAR money += -1000
                    018C: play_sound 1053 at 0.0 0.0 0.0
    
                    wait 3000
                   car.RemoveReferences(MISSION_CAR)
                   mission_cleanup
                   jump @back_the_top
                  
            end
            if or 
            car.Wrecked(MISSION_CAR)
            02BF:   car MISSION_CAR sunk
            then
                    show_styled_text "~r~You destroyed the car! ~w~Pay! $3000" 3000 5 
                    0109: player $PLAYER_CHAR money += -3000
                    018C: play_sound 1053 at 0.0 0.0 0.0
            
                 wait 3000
                 car.RemoveReferences(MISSION_CAR)
                 mission_cleanup
                 jump @back_the_top
            end 
            if   
            8205:  not actor $PLAYER_ACTOR near_car MISSION_CAR radius 80.0 80.0 80.0 flag 0
    
            then
                    show_styled_text "~r~You abanadon the car without bring it back! ~w~Pay! $1500" 3000 5 
                    0109: player $PLAYER_CHAR money += -1500
                    018C: play_sound 1053 at 0.0 0.0 0.0
            
                 wait 3000
                 car.RemoveReferences(MISSION_CAR)
                 mission_cleanup
                 jump @back_the_top
            end 
            0E65: get_car_collision_intensity MISSION_CAR store_to 200@  
            0E66: get_car_collision_coordinates MISSION_CAR store_to 201@ 202@ 203@     
        
           damage_dealt=car.Health( MISSION_CAR )
           if and
           damage_dealt >= 30000
            200@ >= 120.0
           then
               damage_dealt=car.Health( MISSION_CAR )
               damage_dealt-=2500
               car.Health( MISSION_CAR )=damage_dealt 
           end 
           if   
            damage_dealt <= 40000
           then
              081D: set_car MISSION_CAR engine_broken 1
              0918: set_car MISSION_CAR engine_operation 0
              car.SetSpeedInstantly( MISSION_CAR,0.0 )
              04FE: deflate_tire 1 on_car MISSION_CAR
    
              if Partice_attach_to_vehicle==0
              then
              066C: 30@ = attach_particle "overheat_car_electric" to_car MISSION_CAR with_offset 0.0 1.5 0.0 rotation 0.0 0.0 0.0 type 1
              064C: make_particle 30@ visible
              Partice_attach_to_vehicle=1
              end
              
           end  
        end  
    end   
 :CLEANUP_MISSION
 $onmission = 0 
 Audiostream.Release( Voice_clip )    
 0650: destroy_particle 30@
 marker.Disable(Location)
 MISSION_CLEANUP
 END_THREAD    
 

 :spawn_player2 
 if coop
 return_if_false
  04C4: store_coords_to 40@ 41@ 42@ from_actor player1 with_offset 1.0 0.0 -1.0
  43@=actor.Angle(player1)
  actor.Angle(player2)=43@
  actor_remove_from_car_and_put_at   player2   40@ 41@ 42@

 return 